package com.sduept.nwld.dataserver.manager.rota;

import com.sduept.core.dao.SuperDAO;
import com.sduept.nwld.dataserver.model.rota.HolidayInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class HolidayManager {
	
	@Autowired
	private SuperDAO dao;	
	/**
	 * 按年获取当年所有节假日信息
	 * @param year
	 * @return
	 */
	public List<HolidayInfo> getAllHolidayByYear(int year){
		return dao.findByCondition("year=?",new Object[]{year}, HolidayInfo.class);
	}
	
	public List<HolidayInfo> getAllHoliday() {
		return dao.findAll(HolidayInfo.class);
	}
	/**
	 * 新增一条节假日信息
	 * @param holidayInfo
	 * @return
	 */
	public HolidayInfo createHolidayInfo(HolidayInfo holidayInfo){
		return dao.create(holidayInfo, HolidayInfo.class);
	}
	
	/**
	 * 编辑一条节假日信息
	 * @param holidayInfo
	 * @return
	 */
	public HolidayInfo updateHolidayInfo(HolidayInfo holidayInfo){
		return dao.update(holidayInfo, HolidayInfo.class);
	}
	
	/**
	 * 按照id获取一条节假日信息
	 * @param id
	 * @return
	 */
	public HolidayInfo findHolidayInfoById(String id){
		return dao.findById(id, HolidayInfo.class);
	}

	/**
	 * 按照id删除一条节假日信息
	 * @param id
	 */
	public void delHolidayInfo(String id){
		dao.delete(id, HolidayInfo.class);
	}
	
	/**
	 * 按照日期查找当日的假日信息
	 * @param date
	 * @return
	 */
	public List<HolidayInfo> findAllHolidayInfoByDate(Date date){
		return dao.findByCondition("holiday=?",new Object[]{date}, HolidayInfo.class);
	}
	/**
	 * 按照日期和名字获取假日信息
	 * @param hdate
	 * @param hname
	 * @return
	 */
	public List<HolidayInfo> findHolidayInfoByHolidayNameAndDate(Date hdate,String hname){
		return  dao.findByCondition("holiday=? and holidayName=?",new Object[]{hdate,hname}, HolidayInfo.class);
	}
	
}
